package result

import (
	"github.com/gofiber/fiber/v2"
	"strconv"
)

// 分页信息
type Pager struct {
	PageIndex int `json:"pageIndex"`
	PageSize  int `json:"pageSize"`
}

var (
	defaultPageIndex = "1"
	defaultPageSize  = "10"
)

// 解析分页
func ParsePager(ctx *fiber.Ctx) (*Pager, error) {
	pageIndex, _ := strconv.Atoi(ctx.Query("pageIndex", defaultPageIndex))
	pageSize, _ := strconv.Atoi(ctx.Query("pageSize", defaultPageIndex))
	return &Pager{
		PageIndex: pageIndex,
		PageSize:  pageSize,
	}, nil
}
